/**
 * 
 */
package client.control;

import java.io.File;
import java.util.concurrent.Callable;

import client.gui.FTPClientWindow;

/**
 * @author FEKIH
 *
 */
public class Downloader implements Callable<Boolean> {

    private SimpleFTP client;
    private String server;
    private String port;
    private FTPClientWindow wind;
    private String user;
    private String pass;
    private File directoryDest;
    private String downloadedFile;

    /**
     * The specific Constructor
     * @param f
     * @param path
     * @param window
     * @param server
     * @param port
     * @param user
     * @param pass
     */
    public Downloader(File f,String path, FTPClientWindow window, String server, String port,
                    String user, String pass) {
    		this.directoryDest	=f ;
    		this.downloadedFile = path;
            this.server = server;
            this.port = port;
            this.wind = window;
            this.user = user;
            this.pass = pass;
            client = new SimpleFTP();
            
    }
    
    
	@Override
	public Boolean call() throws Exception {
        System.out.println("DOWNLOAD starting for " + downloadedFile );
        Boolean result = false;
        client.connect(server, Integer.parseInt(port), user, pass);
        result = client.getData(downloadedFile,directoryDest);
        if (result) {
                wind.console.append("Successfully transfered file "
                                + downloadedFile);
                System.out.println("Successfully transfered file "
                                + downloadedFile);
                
        } else {
                wind.console.append("Failed transfering file " + downloadedFile);
                System.out.println("Successfully transfered file "
                                + downloadedFile);
        }
        return result;
	}

}
